package com.yidu.sanrenxing.crudall.service.impl;

import com.yidu.sanrenxing.crudall.dao.ShoppingMapper;
import com.yidu.sanrenxing.crudall.domain.Shopping;
import com.yidu.sanrenxing.crudall.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ShoppingServiceImpl implements ShoppingService {
    @Autowired
    ShoppingMapper shoppingMapper;

    @Override
    public List<Shopping> selectByUserId(int userid) {
        return shoppingMapper.selectByUserId(userid);
    }

    @Override
    public List<Shopping> selectAll() {
        return shoppingMapper.selectAll();
    }


    @Override
    public int deleteByPrimaryKey(int shoppingid) {
        return shoppingMapper.deleteByPrimaryKey(shoppingid);
    }

    @Override
    public int insert(Shopping record) {
        return shoppingMapper.insert(record);
    }

    @Override
    public int insertSelective(Shopping record) {
        return shoppingMapper.insertSelective(record);
    }

    @Override
    public Shopping selectByPrimaryKey(int shoppingid) {
        return shoppingMapper.selectByPrimaryKey(shoppingid);
    }

    @Override
    public int updateByPrimaryKeySelective(Shopping record) {
        return shoppingMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Shopping record) {
        return shoppingMapper.updateByPrimaryKey(record);
    }

    @Override
    public Integer deleteShoppingCarMsgByComIdAndUserId(Integer comId, Integer userId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("comId",comId);
        return shoppingMapper.deleteShoppingCarMsgByComIdAndUserId(map);
    }

    @Override
    public Integer queryUserIdAndComIdIfExit(Integer userId, Integer comId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("comId",comId);
        return shoppingMapper.queryUserIdAndComIdIfExit(map);
    }

    @Override
    public Integer updateShoppingCarById(Integer shoppingId, Integer shoppingNum) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("shoppingId",shoppingId);
        map.put("shoppingNum",shoppingNum);
        return shoppingMapper.updateShoppingCarById(map);
    }
}
